class httpRequest{
  static baseUrl = "http://47.108.197.28:";
  static http(url){
    return new Promise((resolve,reject)=>{
      wx.request({
        url,
        dataType: "json",
        header: {"content-type":"application"},
        method: "GET",
        responseType: "text",
        success: (result) => {resolve(result)},
        fail: (res) => {reject(res)},
      })
    })
  }
}

class getPosition extends httpRequest{
  static getLocal(){
    return new Promise((resolve,reject)=>{
      wx.getLocation({
        type:"wgs84",
        altitude: false,
        success:res=>resolve(res),
        fail:err=>reject(err)
      })
    })
  }
  static getCountry(latitude,longitude){
    var key = "FS4BZ-4S4WI-72LGM-5ALZR-VDPEV-DSFTF";
    var url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}&get_poi=1`;
    return this.http(url);
  }
}

class musicHttp extends httpRequest{
  static getBanner(){
    return this.http(this.baseUrl+"3000/banner");
  }
  static getHotMusic(){
    return this.http(this.baseUrl+"3000/top/playlist/highquality")
  }
  static getNewest(){
    return this.http(this.baseUrl+"3000/album/newest")
  }
  static getDjProgram(){
    return this.http(this.baseUrl+"3000/personalized/djprogram")
  }
  static searchSong(keyword){
    return this.http(this.baseUrl+`3000/search?keywords=${keyword}`)
  }
  static searchDetail(id){
    return this.http(this.baseUrl+`3000/song/detail?ids=${id}`)
  }
}

class mvHttp extends httpRequest{
  static getBanner(){
    return this.http(this.baseUrl+"4000/api/banner")
  }
  static getTop250(){
    return this.http(this.baseUrl+"4000/api/movie/top250")
  }
  static getComingSoon(){
    return this.http(this.baseUrl+"4000/api/movie/comingSoon")
  }
  static getInTheaters(){
    return this.http(this.baseUrl+"4000/api/movie/inTheaters")
  }
}
module.exports = {
  musicHttp,
  mvHttp,
  getPosition
}